<?php
/**
 * Created by PhpStorm.
 * User: ASUS
 * Date: 2018/4/2
 * Time: 21:00
 */

namespace Clients;


class Client
{
    private $client;

    public function __construct() {
        $this->client = new \swoole_client(SWOOLE_SOCK_UDP);
    }

    public function connect() {
        if( !$this->client->connect("127.0.0.1", 9501 , 1) ) {
            exit("connect failed. Error: {$this->client->errCode}\n");
        }

        // php cli 常量
        fwrite(STDOUT, "请输入消息:\n");
        $msg = trim(fgets(STDIN));

        $this->client->sendto('127.0.0.1', 9501,  $msg);

    }
}

$client = new Client();
$client->connect();